#include "menu_button.h"

MenuButton::MenuButton() : SDLGameObject() {

}

void MenuButton::Load(const LoadParams* params) {
    SDLGameObject::Load(params);
    callback_id_ = params->get_callback_id();
    current_frame_ = kMouseOut;
}

void MenuButton::Draw() {
    SDLGameObject::Draw();
}

void MenuButton::Update() {
    Vector2D* mouse_pos = TheIH::instance().get_mouse_position();

    if (mouse_pos->getx() > position_.getx() && mouse_pos->getx() < position_.getx() + width_ &&
        mouse_pos->gety() > position_.gety() && mouse_pos->gety() < position_.gety() + height_) {

        if (TheIH::instance().get_mouse_button_states_(kLeft) && released_) {
            current_frame_ = kClicked;
            call_back_();
            released_ = false;
        }
        else if (!TheIH::instance().get_mouse_button_states_(kLeft)) {
            released_ = true;
            current_frame_ = kMouseOver;
        }
    }
    else {
        current_frame_ = kMouseOut;
    }
}

void MenuButton::Clean() {
    SDLGameObject::Clean();
}

